package com.se.utils;

public class UsernameOrGroupId {
    private String username = null;
    private int groupId = -1;

    public UsernameOrGroupId(String username) {
        if(ServiceUtils.isInteger(username)) {
            this.groupId = Integer.parseInt(username);
            return;
        }
        this.username = username;
    }

    public UsernameOrGroupId(int groupId) {
        this.groupId = groupId;
    }

    @Override
    public boolean equals(Object obj) {
        if(!(obj instanceof UsernameOrGroupId)) {
            return false;
        }

        if(((UsernameOrGroupId) obj).username == null) {
            return groupId == ((UsernameOrGroupId) obj).groupId;
        }
        else {
            return username.equals(((UsernameOrGroupId) obj).username);
        }
    }

    @Override
    public int hashCode() {
        if(username == null) {
            return groupId;
        }
        else {
            return username.hashCode();
        }
    }
}
